import time

from selenium import webdriver
from selenium.webdriver.common.by import By

# 创建浏览器驱动对象
driver= webdriver.Edge()
driver.maximize_window()
#打开页面
driver.get("http://localhost:82/index.php")

driver.find_element(By.CSS_SELECTOR,'.red').click()
driver.find_element(By.CSS_SELECTOR,'#username').send_keys("13800138006")
driver.find_element(By.CSS_SELECTOR,'#password').send_keys("123456")
driver.find_element(By.CSS_SELECTOR,'#verify_code').send_keys("8888")
driver.find_element(By.CSS_SELECTOR,"a[name='sbtbutton']").click()

time.sleep(1)
driver.find_element(By.CSS_SELECTOR,"a[href='/index.php/Home/Index/index.html']").click()

# 搜索


driver.find_element(By.CSS_SELECTOR,'#q').send_keys("手机")

# 点击搜索
driver.find_element(By.CSS_SELECTOR,"button[type='submit']").click()
# 点击第一个商品
driver.find_element(By.CSS_SELECTOR,"body > div:nth-child(7) > div:nth-child(1) > div:nth-child(2) > div:nth-child(2) > ul:nth-child(1) > li:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)").click()
#goods_spec_a_13
driver.find_element(By.CSS_SELECTOR,"#goods_spec_a_13").click()
driver.find_element(By.CSS_SELECTOR,"#goods_spec_a_17").click()

# time.sleep(3)
# driver.find_element(By.CSS_SELECTOR,"#number").clear()  #清除   全选
time.sleep(3)
driver.find_element(By.CSS_SELECTOR,"#number").send_keys("2")  #清除
time.sleep(3)
driver.find_element(By.CSS_SELECTOR,"#buy_now").click()


time.sleep(10)


#关闭浏览器驱动对象
driver.quit()
